package com.ecar.oauth.provider.beans;

import com.ecar.common.cipher.DES;
import com.ecar.common.util.PropertyUtil;
import com.ecar.common.util.SpringContextUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created by 30 on 2016/6/22.
 */
public class OAuthPasswordEncoder implements PasswordEncoder {

	@Override
	public String encode(CharSequence rawPassword) {
		PropertyUtil propertyUtil = (PropertyUtil) SpringContextUtil.getBean("propertyUtil");
		String key = propertyUtil.getValue("security.pwd.key");
		return DES.encrypt(key, rawPassword.toString());
	}

	@Override
	public boolean matches(CharSequence rawPassword, String encodedPassword) {
		return encodedPassword.equals(encode(rawPassword));
	}
}
